package book.security;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.math.BigInteger;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;

public class KeyStoreTest2 {

	public static void main(String[] args) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException {
		
		FileInputStream in = new FileInputStream("/Users/apple/Documents/demo.keystore");
		KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
		store.load(in, "123456".toCharArray());
		in.close();
		
//		KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)store.getEntry("ss", "123456".toCharArray());
//		PrivateKey key = pkEntry.getPrivateKey();
		
		PrivateKey key2 = (PrivateKey)store.getKey("ss", "123456".toCharArray());
		System.out.println(new BigInteger(key2.getEncoded()));
	}
}
